const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    entry: {
        // base:'./public/js/base.js',
        script:'./public/js/index.js'
    },
    output: {
        path: path.resolve(__dirname,'./dist/js'),
        filename: "[name]-[hash].js"
    },
    module: {
        rules: [
            { test: /\.css$/, loader: ['style-loader','css-loader'] },
            {
                test:/\.(sass|scss)$/,
                use:['style-loader','css-loader','sass-loader']
            },
            {
                test: /\.less$/,
                use: [{
                    loader: "style-loader" 
                    }, 
                    {
                        loader: "css-loader" 
                    },
                    {
                        loader: "less-loader"
                    }
                ]
            },
            {
                test:/\.(png|jpg|gif)$/,
                use:[{
                    loader:'url-loader',
                    options:{ // 这里的options选项参数可以定义多大的图片转换为base64
                        limit:50000, // 表示小于50kb的图片转为base64,大于50kb的是路径
                        outputPath:'images' //定义输出的图片文件夹
                    }
                }],
            },    
            {
                test:/\.js$/, //匹配.js文件
                //排除也就是不转换node_modules下面的.js文件
                exclude: /(node_modules|bower_components)/,
                //加载器  webpack2需要loader写完整 不能写babel 要写 bable-loader
                use:[{loader:"babel-loader"}]
            },
            // { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
            // { test: /\.(woff|woff2)$/, loader:"url?prefix=font/&limit=5000" },
            // { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
            // { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" },
            {
                test: /\.(eot|svg|ttf|woff|woff2)\w*/,
                loader: 'url-loader?limit=1000000'
              },
        ]
    },
    plugins:[
        new htmlWebpackPlugin({
            template:'index.html',
            title:'li'
            // filename:'',
            // inject:'head'
            // title date minify
            // chunks:['main']
        })
    ],
    devServer: {
        contentBase: path.resolve(__dirname, 'dist'),
    }
};